﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TankWar
{
    public partial class Form1 : Form
    {
        Thread t;
        static Graphics g;
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            g = this.CreateGraphics();
            GameFramework.g =g; 

            t = new Thread(new ThreadStart(GameMainThread));
            t.Start();
        }

        // 写一个供线程调用的方法
        private static void GameMainThread()
        {
            GameFramework.Start();
            int sleepTime = 1000/60;            
            while (true)    // 注意这里的处理有点简单粗暴，并不是说任何时候都需要调用Update
            {
                g.Clear(Color.Black);
                GameFramework.Update();
                Thread.Sleep(sleepTime);
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            t.Abort();
        }
    }
}
